package com.jinpin.product.controller;

import cn.hutool.core.date.DateTime;
import com.jinpin.api.module.Storage.StorageFeign;
import com.jinpin.core.dto.ArticleDto;
import com.jinpin.product.entity.WorkOrder;
import com.jinpin.product.service.WorkOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class WorkOrderController {

    @Autowired
    private WorkOrderService workOrderService;

    @Autowired
    private StorageFeign storageFeign;

    @GlobalTransactional
    @PostMapping("/newWorkOrder")
    public String newWorkOrder(){
        // 绑定订单

        // 设置物料

        // 生成预约

        WorkOrder workOrder = new WorkOrder(1L,"wsxss",
                12321123L,20.0,12342L,
                1,0L,"小明",
                new DateTime().toJdkDate(),"小明",new DateTime().toJdkDate());

        workOrderService.save(workOrder);
        // 更新物料需求量
        storageFeign.updateArticle(new ArticleDto().setArticleId(1L).setNeeds(20D));


        return "新工单生成成功";
    }
}
